package com.example.its2021606134chh.TrafficQueryModule;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.example.its2021606134chh.R;

/**
 * @ClassName: ParkingLotShow$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 4/9/2021$
 * @Version: 1.0
 */
public class ParkingLotShow extends View {
    private int color = R.color.white;
    public void setState(int state) {
        switch (state) {
            case 1:
                this.color = R.color.colorOpen;
                break;
            case 2:
                this.color = R.color.colorSlow;
                break;
            case 3:
                this.color = R.color.colorGeneralCongestion;
                break;
            case 4:
                this.color = R.color.colorModerateCongestion;
                break;
            case 5:
                this.color = R.color.colorSevereCongestion;
                break;
        }
    }
    public ParkingLotShow(Context context) {
        super(context);
    }

    public ParkingLotShow(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int stroke=200;
        int left = getLeft();
        int top = getTop();
        int right = getRight();
        int bottom = getBottom();
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(getResources().getColor(color, null));
        RectF oval3 = new RectF(left, top, left+stroke, bottom);
        canvas.drawRoundRect(oval3, 20, 15, paint);
    }
    @Override
    public void invalidate() {
        super.invalidate();
    }
}
